package file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

//InputStream用法
public class Demo7 {
    public static void main(String[] args) throws IOException {
        try(InputStream inputStream = new FileInputStream("d:/test.txt")) {
            //文本文件也可以使用字节流打开,只不过此时读到的每个字节,就不是完整字符了
            while (true){
                byte[] buf = new byte[1024];
                int n = inputStream.read(buf);
                if (n == -1){
                    break;
                }
                for (int i = 0; i < n;i++){
                    System.out.print(buf[i]+ " ");
                }
                String s = new String(buf,0,n);//字节数组转成字符串
                System.out.println(s);
            }
        }
    }
}
